package com.beidouapp.security.mvc.convert;

import java.io.IOException;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.ser.CustomSerializerFactory;

public class CustomerObjectMapper extends ObjectMapper
{
	public CustomerObjectMapper()
	{
		super();
		this.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
		CustomSerializerFactory factory = new CustomSerializerFactory();
		factory.addGenericMapping(Date.class, new JsonSerializer<Date>()
		{
			@Override
			public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException
			{
				jsonGenerator.writeNumber(value.getTime());
			}
		});
		this.setSerializerFactory(factory);
	}
}
